"""
__author__="yanwei"
__describe__="统一登录平台登录页面，把登录页面封装成一个类型，一个元素一个方法，给测试用例进行调用"
"""

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from Pages.BasePage import Base_Page
from Drivers.browser_driver import BrowserDriver
from Pages.unify_management_center import UnifyManagementCenter

class UnifyLoginPage():


    def account(self,driver,name):
        """
        定位登录页面【账号】输入框
        :param driver: 调用浏览器驱动
        :param name: 登录账号
        :return: 输入登录账号
        """
        account = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入账号/手机号']")
        return account.send_keys(name)

    def password(self,driver,pwd):
        """
        定位登录页面【密码】输入框
        :param drvier: 调用浏览器驱动
        :param pwd: 登录密码
        :return: 输入登录密码
        """
        password = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入密码']")
        return password.send_keys(pwd)

    def get_ver_code(self,driver):
        """
        定位【获取验证码】点击框
        :param driver:调用浏览器驱动
        :return:点击获取验证码
        """
        get_ver_code = driver.find_element(By.ID,"captcha_img")
        return get_ver_code.click()


    def input_ver_code(self,driver,code):
        """
        定位【验证码】输入框
        :param driver:调用浏览器驱动
        :param code: 验证码
        :return: 输入登录验证码
        """
        input_ver_code = driver.find_element(By.CSS_SELECTOR,"input[placeholder='请输入验证码']")
        return input_ver_code.send_keys(code)

    def login(self,driver):
        """
        定位【登录】按钮点击框
        :param driver: 调用浏览器驱动
        :return: 点击登录按钮进行登录操作
        """
        login = driver.find_element(By.CLASS_NAME,"el-button--primary")
        return login.click()



if __name__=="__main__":
    # driver = Base_Page().browser_chrome(url="http://192.168.6.75:8088/#/loginStandby")
    driver = BrowserDriver().browser_chrome(url = "http://test.user.1688sup.com/#/login")
    driver.maximize_window()
    UnifyLoginPage().account(driver=driver,name="18380416326")
    UnifyLoginPage().password(driver=driver,pwd="cs123456")
    UnifyLoginPage().input_ver_code(driver=driver,code = "123456")
    UnifyLoginPage().login(driver=driver)
    time.sleep(6)
    UnifyManagementCenter().blessing_button(driver=driver)
    UnifyManagementCenter().market_system_button(driver=driver)

    time.sleep(5)

    driver.quit()

